import "./public-path";
import { type App as InsApp, createApp } from "vue";
import App from "./App.vue";
import _router from "./router/index";
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './theme.css'

let app: InsApp;
let router = null;
function render(props: any = {}) {
  const { container } = props;
  app = createApp(App);
  router = _router;
  app.use(_router);
  app.use(ElementPlus);
  app.mount(container ? container.querySelector("#app") : "#app");
}

// 非qiankun环境下
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function bootstrap() {
  console.log("vue app bootstraped");
}

export async function mount(props: any) {
  console.log("vue app mount", props);
  render(props);
}

export async function unmount(props: any) {
  console.log("vue app unmount", props);
  app!.unmount();
  router = null;
}

(window as any).customEventBus.emit("sub-webpack-vue", {
  content: "Hello from child app!",
});
